<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>校园宿舍管理系统 - 宿舍详情</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark" style="background-color: #17a589;">
    <div class="container">
        <a class="navbar-brand" href="#">校园宿舍管理系统</a>
        <div class="collapse navbar-collapse">
            <ul class="navbar-nav me-auto">
                <li class="nav-item">
                    <a class="nav-link" th:href="@{/home}">首页</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" th:href="@{/student/list}">学生管理</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link active" th:href="@{/dormitory/list}">宿舍管理</a>
                </li>
            </ul>
            <div class="d-flex">
                <span class="navbar-text me-3" th:text="'欢迎，' + ${session.user.username}"></span>
                <a class="btn btn-outline-light" th:href="@{/user/logout}">退出</a>
            </div>
        </div>
    </div>
</nav>
<div class="container mt-4">
    <div class="row mb-3">
        <div class="col-md-6">
            <h2>宿舍详情</h2>
        </div>
        <div class="col-md-6 text-end">
            <a class="btn btn-outline-primary" th:href="@{/dormitory/edit/} + ${dormitory.id}">编辑</a>
            <a class="btn btn-outline-secondary" th:href="@{/dormitory/list}">返回列表</a>
        </div>
    </div>

    <div class="row mb-4">
        <div class="col-md-8 mx-auto">
            <div class="card">
                <div class="card-header">
                    <h4 th:text="${dormitory.building + '-' + dormitory.dormitoryNumber}">宿舍信息</h4>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-6">
                            <p><strong>宿舍楼:</strong> <span th:text="${dormitory.building}"></span></p>
                            <p><strong>楼层:</strong> <span th:text="${dormitory.floor}"></span></p>
                            <p><strong>宿舍类型:</strong> <span th:text="${dormitory.type}"></span></p>
                            <p><strong>容量:</strong> <span th:text="${dormitory.capacity}"></span> 人</p>
                        </div>
                        <div class="col-md-6">
                            <p><strong>已入住:</strong> <span th:text="${dormitory.occupied}"></span> 人</p>
                            <p><strong>状态:</strong>
                                <span th:classappend="${dormitory.status == '空宿舍' ? 'badge bg-secondary' :
                                                     dormitory.status == '部分入住' ? 'badge bg-warning' : 'badge bg-danger'}">
                                    <span th:text="${dormitory.status}"></span>
                                </span>
                            </p>
                            <p><strong>空闲床位:</strong>
                                <span th:classappend="${dormitory.occupied < dormitory.capacity ? 'text-success' : 'text-danger'}">
                                    <span th:text="${dormitory.capacity - dormitory.occupied}"></span> 个
                                </span>
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-md-10 mx-auto">
            <div class="card">
                <div class="card-header">
                    <h4>入住学生信息</h4>
                </div>
                <div class="card-body">
                    <div th:if="${#lists.isEmpty(students)}" class="alert alert-info">
                        该宿舍目前没有学生入住
                    </div>
                    <table th:if="${not #lists.isEmpty(students)}" class="table table-striped table-hover">
                        <thead>
                        <tr>
                            <th>姓名</th>
                            <th>性别</th>
                            <th>年龄</th>
                            <th>专业</th>
                            <th>班级</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="student : ${students}">
                            <td th:text="${student.name}"></td>
                            <td th:text="${student.gender}"></td>
                            <td th:text="${student.age}"></td>
                            <td th:text="${student.major}"></td>
                            <td th:text="${student.className}"></td>
                            <td>
                                <a th:href="@{/student/edit/{id}(id=${student.id})}" class="btn btn-sm btn-outline-primary">编辑</a>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>